//Source file: D:\\test\\com\\ce\\pms\\customer\\model\\ParticipantDO.java

package com.ce.pms.customer.model;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;

import org.hibernate.annotations.Where;

import com.ce.pms.common.model.SysInfo;
import com.sitechasia.webx.core.model.IDomainObject;

/**
 * 实体名称:参与人 关系表：CS_PARTICIPANT
 * @author Adama Yue
 */
@Entity
@Table(name = "CS_PARTICIPANT")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class ParticipantDO implements IDomainObject{
	@Id
	@GeneratedValue
	@Column(name = "PARTICIPANT_ID")
	private Long participantId;

	/**
	 * 检索策略:lazy=true 级联配置:cascade=save-update
	 */
	@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "participant1")
	@org.hibernate.annotations.Cascade(value = { org.hibernate.annotations.CascadeType.SAVE_UPDATE })
	private Set<ParticipantRelationDO> forwardRelations = new HashSet<ParticipantRelationDO>();

	/**
	 * 检索策略:lazy=true 级联配置:cascade=save-update
	 */
	@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "participant2")
	@org.hibernate.annotations.Cascade(value = { org.hibernate.annotations.CascadeType.SAVE_UPDATE })
	private Set<ParticipantRelationDO> reverseRelations = new HashSet<ParticipantRelationDO>();


	@Column(name="PARTICIPANT_NAME",nullable=false,insertable=true,updatable=true,length=80)
	private String participantName;//参与人姓名

	@Column(name="TELEPHONE",nullable=true,insertable=true,updatable=true,length=80)
	private String telephone;//联系电话

	@Embedded
	private SysInfo sysInfo;//系统信息（创建，修改信息）

	public ParticipantDO() {
	}
	/**
	 * mini constructor
	 * @param participantName 参与人姓名
	 * @param sysInfo 系统信息（创建，修改信息）
	 */
	public ParticipantDO(String participantName, SysInfo sysInfo) {
		super();
		this.participantName = participantName;
		this.sysInfo = sysInfo;
	}
	/**************************************************
	 * Bussiness code
	 **************************************************/
	/**
	 * get all relationships of the particepant ,whatever forward or reverse
	 */
	public Set<ParticipantRelationDO> getRelations() {
		Set<ParticipantRelationDO> retValue = new HashSet<ParticipantRelationDO>();
		retValue.addAll(getForwardRelations());
		retValue.addAll(getReverseRelations());
		return retValue;
	}

	/**
	 * retrive relative relations
	 */
	public Set<ParticipantRelationDO> getRelativeRelations() {
		Set<ParticipantRelationDO> retValue = new HashSet<ParticipantRelationDO>();
			for(ParticipantRelationDO relation : this.getRelations()) {
			String i = relation.getRelationType().getRelationTypeCode();
			switch (Integer.valueOf(i)) {
			case 1:
			case 2:
			case 3:
			case 4:
			case 5:
				retValue.add(relation);
			break;
			}
		}
		return retValue;
	}

	/**************************************************
	 * Accessors and Modifiers
	 **************************************************/
	public Long getParticipantId() {
		return participantId;
	}
	public void setParticipantId(Long participantId) {
		this.participantId = participantId;
	}
	public String getParticipantName() {
		return participantName;
	}
	public void setParticipantName(String participantName) {
		this.participantName = participantName;
	}
	public SysInfo getSysInfo() {
		return sysInfo;
	}
	public void setSysInfo(SysInfo sysInfo) {
		this.sysInfo = sysInfo;
	}
	public String getTelephone() {
		return telephone;
	}
	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}
	public Set<ParticipantRelationDO> getForwardRelations() {
		return forwardRelations;
	}
	public void setForwardRelations(Set<ParticipantRelationDO> forwardRelations) {
		this.forwardRelations = forwardRelations;
	}
	public Set<ParticipantRelationDO> getReverseRelations() {
		return reverseRelations;
	}
	public void setReverseRelations(Set<ParticipantRelationDO> reverseRelations) {
		this.reverseRelations = reverseRelations;
	}




}
